package com.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import com.sina.sae.util.SaeUserInfo;
public class dbcon {

	private static Connection con= null ;
    
	public static void closeConn() {
        try {
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
	public static Connection getConnection(){
		String driver="com.mysql.jdbc.Driver";
//		String dbusername="root";
//		String dbpwd = "123456";
//		String dbname = "yijing";
//		String url="jdbc:mysql://localhost:3306/"+dbname;
		String dbusername=SaeUserInfo.getAccessKey();
		String dbpwd = SaeUserInfo.getSecretKey();
		String appname = SaeUserInfo.getAppName();
		String url="jdbc:mysql://r.rdc.sae.sina.com.cn:3307/app_"+appname+"?autoReconnect=true";
		try{
			Class.forName(driver).newInstance();
			System.out.println("dbusername : "+dbusername);
			System.out.println("dbpwd : "+dbpwd);
//			System.out.println("appname : "+appname);
			con = DriverManager.getConnection(url,dbusername,dbpwd);
		}catch (Exception e){
			e.printStackTrace();
			System.out.println("数据库连接失败"+e.getMessage());
		}
		return con;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Connection conn = null;
        conn = getConnection();
        System.out.println("test");
        if (conn != null) {
            System.out.println("hehll");
        } else {
            System.out.println("dafsdfa");
        }
	}

}
